package modelLayer;

import java.util.ArrayList;

public class ClassRoomCon {
	
	private ArrayList<ClassRoom> roomList;
	private static ClassRoomCon instance;
	
	public ClassRoomCon() {
		
		roomList = new ArrayList<>();
	}
	
	public static ClassRoomCon getInstance() {
		
		if(instance == null) {
			
			instance = new ClassRoomCon();
		}
		
		return instance;
	}
	
	public void addRoom(ClassRoom classRoom) {
		
		roomList.add(classRoom);
		
	}
	
	public void removeClass(int index) {
		
		roomList.remove(index);
	}
	
	public ArrayList<ClassRoom> getAll() {
		
		return roomList;
	}
	
	public ClassRoom findByName(String name) {
		
		ClassRoom classRoom = null;
		boolean found = false;
		
		for(int i = 0; i < roomList.size() && !found; i++ ) {
			
			if(roomList.get(i).getName().equals(name)){
				classRoom = roomList.get(i);
				found = true;
			}
		}
		return classRoom;
		
	}
	

}
